/**
 * HanLPTokenizer.java
 *
 * @author ZhuJiahui1991
 * @date 2017年11月12日
 */
package com.zhujiahui.nlp.core.tokenizer;

import java.util.List;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.seg.Segment;
import com.hankcs.hanlp.seg.common.Term;
import com.zhujiahui.nlp.core.domain.IndexToken;
import com.zhujiahui.nlp.core.domain.Token;

/**
 * @description
 * 
 * @author ZhuJiahui1991
 * @date 2017年11月12日
 * 
 */
public class HanLPTokenizer extends AbstractTokenizer {
	
	// HanLP Segment
	private Segment segment = null;

	/**
	 * 默认构造函数
	 */
	public HanLPTokenizer() {
		segment = HanLP.newSegment();
		this.segment.enableOrganizationRecognize(true);
		this.segment.enableJapaneseNameRecognize(true);
		this.segment.enablePlaceRecognize(true);
		//this.segment.enableAllNamedEntityRecognize(true);
		this.segment.enableCustomDictionary(true);
	}

	/* (non-Javadoc)
	 * @see com.zhujiahui.zhunlp.tokenizer.AbstractTokenizer#segment(java.lang.String)
	 */
	@Override
	public List<Token> segment(String sentence) {
		List<Term> termList = this.segment.seg(sentence);
		if (this.isSymbolMerged) {
			return this.postMergeSegment(termList);
		} else {
			return this.postSegment(termList);
		}
	}

	/* (non-Javadoc)
	 * @see com.zhujiahui.zhunlp.tokenizer.AbstractTokenizer#segmentWithIndex(java.lang.String)
	 */
	@Override
	public List<IndexToken> segmentWithIndex(String sentence) {
		// TODO Auto-generated method stub
		return null;
	}

}
